/*

 * and open the template in the editor.
 */

package hcmus.fit.master.sevensea.control;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;

/**
 * 
 * @author hvp
 */
public class Life {
    public static List Resources;
    public int LIFE;
    public static Bitmap Icon;

    public Life(int life) {
        LIFE = life;
    }

    public void Show(Canvas g, int x, int y) {

        List list = new ArrayList();
        int life = LIFE;
        while (life > 0) {
            list.add(new Integer(life % 10));
            life /= 10;
        }
        if (list.size() <= 0)
            list.add(new Integer(0));

        x -= (list.size() * 23 / 2);

        // g.drawImage(Icon,x - 20, y-2, Graphics.TOP|Graphics.LEFT);
        // g.drawImage(Icon, new Rectangle(x - 25, y, Icon.Width * 2 / 3,
        // Icon.Height * 2/ 3), 0, 0, Icon.Width, Icon.Height,
        // GraphicsUnit.Pixel, imgatt);

        for (int i = 0; i < list.size(); i++) {
            // int num = ((Integer)list.get(list.size()-i-1)).intValue();
            // Image tmp = (Image) Resources.get(num);
            // int w = tmp.getWidth();
            // g.drawImage(tmp, x + i*w, y, Graphics.TOP|Graphics.LEFT);
            // ImageAttributes imgatt = new ImageAttributes();
            // imgatt.SetColorKey(tmp.GetPixel(0, 0), tmp.GetPixel(0, 0));
            // g.DrawImage(tmp, new Rectangle(x + i*(w * 2 / 3), y, w * 2 / 3, h
            // * 2 /3), 0, 0, tmp.Width, tmp.Height,
            // GraphicsUnit.Pixel, imgatt);
        }

    }

    public static List GetResource(Bitmap resource, int maxX, int maxY, int numerator, int denominator) {
        List rs = new ArrayList();
        int w = resource.getWidth() / maxX;
        int h = resource.getHeight() / maxY;
        int w1 = resource.getWidth() / maxX * numerator / denominator;
        int h1 = resource.getHeight() / maxY * numerator / denominator;
        // ImageAttributes imgatt = new ImageAttributes();
        // imgatt.SetColorKey(resource.GetPixel(0, 0), resource.GetPixel(0, 0));

        for (int i = 0; i < maxY; i++) {
            for (int j = 0; j < maxX; j++) {
                // Image tmp = Image.createImage(w, h);
                // Graphics g = tmp.getGraphics();
                // g.drawImage(resource, 0, 0, Graphics.TOP|Graphics.LEFT);
                // g.DrawImage(resource, new Rectangle(0, 0, w1, h1), j * w, i *
                // h, w, h, GraphicsUnit.Pixel, imgatt);
                // g.Dispose();
                // rs.add(tmp);
            }
        }
        return rs;
    }
}
